package com.lyt.mall.order.utils;

import com.alibaba.fastjson.JSON;
import com.lyt.common.constant.OrderConstant;
import com.lyt.common.dto.SeckillOrderDTO;
import com.lyt.mall.order.service.OrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: LiuYutong
 */
@Component
@RocketMQMessageListener(topic = OrderConstant.ROCKETMQ_SECKILL_ORDER_TOPIC,consumerGroup = "test")
public class SeckillOrderConsumer implements RocketMQListener<String> {

    @Autowired
    OrderService orderService;

    @Override
    public void onMessage(String message) {
        //订单关单的逻辑实现
        SeckillOrderDTO orderDTO = JSON.parseObject(message,SeckillOrderDTO.class);
        orderService.quickCreateOrder(orderDTO);
    }
}
